import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../js_widget/js_image_view.dart';
import '../js_widget/js_style.dart';
import '../js_widget/js_text_ghosting_view.dart';

jsShowGameFailureDialog(
  BuildContext context, {
  required Function onRestart,
}) {
  bool flag = Random().nextBool();

  showDialog(
    context: context,
    barrierDismissible: false,
    useSafeArea: false,
    barrierColor: Colors.black.withOpacity(0.55),
    builder: ((context) {
      return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Dialog(
            alignment: Alignment.center,
            insetPadding: EdgeInsets.zero,
            backgroundColor: Colors.transparent,
            child: Container(
              height: 402.r,
              padding: EdgeInsets.symmetric(horizontal: 28.r),
              alignment: Alignment.topCenter,
              child: Stack(
                alignment: Alignment.topCenter,
                children: [
                  jsImage('assets/image/ic_game_first_tips_bg.png', height: 402.r, fit: BoxFit.fitHeight),
                  jsImage(flag ? 'assets/gif/ic_game_failure_1.gif' : 'assets/gif/ic_game_failure_2.gif', height: 83.r, fit: BoxFit.fitHeight, padding: EdgeInsets.only(top: 127.r)),
                  Positioned(
                    left: 31.r,
                    top: 217.r,
                    right: 31.r,
                    child: Text('Not your best run, but there’s always next time!', textAlign: TextAlign.center, style: jsTextStyle(font: JsTextFont.PoetsenOne, fontColor: Color(0xFF3B0C27), fontSize: 20.r, height: 30.0 / 20)),
                  ),
                  Positioned(
                    left: 28.r,
                    right: 28.r,
                    bottom: 21.r,
                    child: InkWell(
                      child: Container(
                        clipBehavior: Clip.antiAlias,
                        decoration: jsShapeRound(radius: 12.r, shadows: [
                          BoxShadow(offset: Offset(0, 2.r), blurRadius: 2.r, color: Colors.black.withOpacity(0.25)),
                        ]),
                        child: Stack(
                          alignment: Alignment.center,
                          children: [
                            jsImage('assets/image/ic_game_start_bg.png', fit: BoxFit.fitWidth),
                            JsTextGhostingView(
                              'Restart',
                              fontSize: 24.r,
                              fontForegroundColor: Colors.white,
                              fontBackgroundColor: Color(0xFFFF3099),
                              fontBorderColor: Color(0xFFFF9BCB),
                              strokeWidthScale: 1.5,
                            ),
                          ],
                        ),
                      ),
                      onTap: () {
                        if (Navigator.canPop(context)) {
                          Navigator.pop(context);
                        }
                        onRestart();
                      },
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      );
    }),
  );
}
